import { inject, injectable } from "inversify";
import { ConfigurationTarget } from "vscode";
import { IDocumentManager, IWorkspaceService } from "../common/application/types";
import { Resource } from "../common/types";
import { EQEnvironment, EnvironmentType } from "../eqEnvironments/info";
import { IServiceContainer } from "../ioc/types";
import { IComponentAdapter, IInterpreterHelper, WorkspaceEQPath } from "./contracts";

@injectable()
export class InterpreterHelper implements IInterpreterHelper {
    constructor(
        @inject(IServiceContainer) private serviceContainer: IServiceContainer,
        @inject(IComponentAdapter) private readonly pyenvs: IComponentAdapter,
    ) { }
    getActiveWorkspaceUri(resource: Resource): WorkspaceEQPath | undefined {
        const workspaceService = this.serviceContainer.get<IWorkspaceService>(IWorkspaceService);
        const hasWorkspaceFolders = (workspaceService.workspaceFolders?.length || 0) > 0;
        if (!hasWorkspaceFolders) {
            return;
        }
        if (Array.isArray(workspaceService.workspaceFolders) && workspaceService.workspaceFolders.length === 1) {
            return { folderUri: workspaceService.workspaceFolders[0].uri, configTarget: ConfigurationTarget.Workspace };
        }

        if (resource) {
            const workspaceFolder = workspaceService.getWorkspaceFolder(resource);
            if (workspaceFolder) {
                return { configTarget: ConfigurationTarget.WorkspaceFolder, folderUri: workspaceFolder.uri };
            }
        }
        const documentManager = this.serviceContainer.get<IDocumentManager>(IDocumentManager);

        if (documentManager.activeTextEditor) {
            const workspaceFolder = workspaceService.getWorkspaceFolder(documentManager.activeTextEditor.document.uri);
            if (workspaceFolder) {
                return { configTarget: ConfigurationTarget.WorkspaceFolder, folderUri: workspaceFolder.uri };
            }
        }
    }
    getInterpreterInformation(eqPath: string): Promise<Partial<EQEnvironment> | undefined> {
        throw new Error("28Method not implemented.");
    }
    isMacDefaultEQPath(eqPath: string): Promise<boolean> {
        throw new Error("29Method not implemented.");
    }
    getInterpreterTypeDisplayName(interpreterType: EnvironmentType): string | undefined {
        throw new Error("30Method not implemented.");
    }
    getBestInterpreter(interpreters?: EQEnvironment[]): EQEnvironment | undefined {
        throw new Error("31Method not implemented.");
    }
}